
const mongoose = require('mongoose');
const _ = require('lodash');
var userService = require('../service/user.service');

module.exports={
    findByUserName:findByUserName,
    findAll:findAll
};

/**
 * find all admin users
 * @param req
 * @param res
 * @param next
 */
function findAll(req,res,next){
    userService.findAll(function(err,docs){
        if(err){
            res.json({result:false,errMsg:'can not find the users'})
        }else {
            res.json({result:true,data:docs});
        }
    });
}

/**
 *
 * @param req
 * @param res
 * @param next
 */
function findByUserName(req,res,next){
    var username = req.params.username;
    if(_.isEmpty(username)){
        next(new Error('id can not be empty'));
    }else {
        userService.findByUserName(username,function(err,data){
            if(err){
                res.json({result:false,errMsg:'can not find the user'})
            }else {
                res.json({result:true,data:data});
            }
        });
    }
}



